<?php
/**
 * Created by PhpStorm.
 * Script Name: MiniTester.php
 * Create: 2023/2/6 14:07
 * Description:
 * Author: fudaoji<fdj@kuryun.cn>
 */

namespace plugin\wechat\app\service;

use EasyOpen\Tencent\Request\Mp\WxaBindTester;
use EasyOpen\Tencent\Request\Mp\WxaMemberAuth;
use EasyOpen\Tencent\Request\Mp\WxaUnbindTester;

class MiniTester extends Mini
{
    /**
     * 移除体验者
     * @param array $params
     * @param array $mini_info
     * @return bool|mixed
     * @throws \EasyWeChat\Kernel\Exceptions\HttpException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * Author: fudaoji<fdj@kuryun.cn>
     */
    public static function testerUnbind($params = [], $mini_info = null){
        $request = new WxaUnbindTester();
        $request->setWechatId($params['wechat_id']);
        $response = self::tencentOpenCli()->execute($request, self::getAccessToken($mini_info));

        if( empty($response['code'])) {
            return $response['errmsg'];
        }
        return true;
    }

    /**
     * 添加体验者
     * @param array $params
     * @param array $mini_info
     * @return bool|mixed
     * @throws \EasyWeChat\Kernel\Exceptions\HttpException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * Author: fudaoji<fdj@kuryun.cn>
     */
    public static function testerAdd($params = [], $mini_info = null){
        $request = new WxaBindTester();
        $request->setWechatId($params['wechat_id']);
        $response = self::tencentOpenCli()->execute($request, self::getAccessToken($mini_info));

        if( empty($response['code'])) {
            return $response['errmsg'];
        }
        return true;
    }

    /**
     * 体验者
     * @param null $mini_info
     * @return mixed
     * @throws \EasyWeChat\Kernel\Exceptions\HttpException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * Author: fudaoji<fdj@kuryun.cn>
     */
    public static function testerGet($mini_info = null){
        $request = new WxaMemberAuth();
        $request->setAction('get_experiencer');
        $response = self::tencentOpenCli()->execute($request, self::getAccessToken($mini_info));
        if(empty($response['code'])){
            return $response['errmsg'];
        }
        return $response['data'];
    }
}